package com.itany.order.service.impl;

import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradePrecreateModel;
import com.alipay.api.request.AlipayTradePrecreateRequest;
import com.alipay.api.response.AlipayTradePrecreateResponse;
import com.itany.order.service.IRoderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by tyh on 2018/9/23.
 */
@Service
@com.alibaba.dubbo.config.annotation.Service
public class OrderServiceImpl implements IRoderService {

    @Autowired
    private AlipayClient alipayClient;

    public String getQrCode() {
        String qrCode = "";
        try {
            String no = System.currentTimeMillis()+"";
            AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
            AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
            model.setOutTradeNo(no);
            model.setTotalAmount("0.01");
            model.setSubject("天下画集");
            request.setNotifyUrl("http://taoyuheng.free.idcfengye.com/order/testorder/paySuccess");
            //request.setReturnUrl();
            request.setBizModel(model);
            AlipayTradePrecreateResponse response = alipayClient.execute(request);
            if(response.isSuccess()){
                System.out.println("success--------"+response.getBody());
            }else{
                System.out.println("error--------"+response.getBody());
            }
            qrCode=response.getQrCode();

        }catch (Exception e){
            e.printStackTrace();
        }

        return qrCode;
    }
}
